package com.satchi.service;

import java.util.List;

import com.satchi.dao.imp.GetReceiptDaoImp;
import com.satchi.hib.pojo.FinCustomer;
import com.satchi.hib.pojo.FinReceipt;
import com.satchi.hib.pojo.FinUser;
import com.satchi.struts.form.FinReceiptExcelForm;

@SuppressWarnings("serial")
public class GetReceiptService extends GetReceiptDaoImp {

	public List<FinReceipt> getPageListNullPar(int pageNo, int pageSize) {
		return getPageList(pageNo, pageSize);
	}

	public FinReceipt get(String id) {
		return getByString(FinReceipt.class, id);
	}

	@Override
	public boolean save(FinReceipt fr) {
		// TODO Auto-generated method stub
		if (fr.equals("")) {
			return false;
		}
		return super.save(fr);
	}

	public FinUser runResultFin(Object[] params) {
		List<FinUser> list = runResulthql(params);
		if (list.size() > 0)
			return list.get(0);
		return null;
	}

	public List<FinReceipt> getPageListPar(int pageNo, int pageSize, Object[] params) {
		return getPage(params, pageNo, pageSize);
	}

	public FinCustomer runResultCus(Object[] params) {
		List<FinCustomer> list = runResulthqlCus(params);
		if (list.size() > 0)
			return list.get(0);
		return null;
	}

	public boolean Close(String ids, String closeDateString) {
		return runNoResultHql(
				"update FinReceipt set isClosed = 'true', closeDate='" + closeDateString + "' where isClosed = 'false' AND receiptId in ("
						+ ids + ")", null);
	}

	public boolean Delete(String ids) {
		return runNoResultHql(
				"delete FinReceipt where isClosed = 'false' AND receiptId in ("
						+ ids + ")", null);
	}

	public List<FinReceipt> getSearchList(String searchKey, int startRow,
			int pageSize) {
		String hql = "from FinReceipt as re where re.finCustomer.customer like '%"
				+ searchKey + "%' order by receiptId";
		return getPageList(hql, startRow, pageSize);
	}

	public Object getMaxId() {
		return getSqlValue(
				"select Right('000000' + cast(isnull(max(receiptId), 0) + 1 as nvarchar(50)), 7) maxID from finReceipt"
				);
	}
}
